<?php
/**
 * Created by PhpStorm.
 * User: FDG296
 * Date: 2017/8/2
 * Time: 16:42
 */
namespace common\models;

use yii\db\ActiveRecord;

class SysConfig extends ActiveRecord{
    const STATUS_ENABLE = 1;
    const STATUS_DISABLE = 0;

    public static function tableName(){
        return '{{%sys_config}}';
    }

    public function rules(){
        return [
            ['use_flg','default','value'=>self::STATUS_DISABLE],
            ['creator','getCreator'],
            ['create_time','date']
        ];
    }

    /**
     * @获取创建人
     */
    public function getCreator(){
        $userInfo = \common\helps\tools::getloginUserInfo();
        if($userInfo){
            $userName = $userInfo->userName;
        }else{
            $userName = '';
        }
        return $userName;
    }

	/**
	 * @param 获取对应分组对应数据
	 */
	public static function getKeyConfig($configGroupId,$configKey,$ext1=''){

		$params = array_filter([
			'config_key'		=>$configKey,
			'config_group_id'	=>$configGroupId,
			'use_flg'			=>self::STATUS_ENABLE,
			'ext1'				=>$ext1
		]);

		return self::find()
			->where($params)
			->one();
	}
}